/*
 * PsMediaWriter.h
 *
 *  Created on: 2018年4月27日
 *      Author: zhengboyuan
 */

#ifndef PSMEDIAWRITER_H_
#define PSMEDIAWRITER_H_

#include "MediaWriter.h"
#include <stdio.h>
#include "PSMuxer.h"
#include "MediaFormat.h"
#include "ByteBuffer.h"

namespace av
{

class PsMediaWriter : public MediaWriter
{
public:
	PsMediaWriter();
	virtual ~PsMediaWriter();

	virtual bool open(const char* filename, const MFormat& fmt);

	virtual void close();

	virtual bool isOpen();

	virtual bool getFormat(MFormat& fmt);

	virtual bool writeVideo(uint8_t* data, int size, int64_t pts, int flags);

	virtual bool writeAudio(uint8_t* data, int size, int64_t pts, int flags);

	virtual int getDuration();

	virtual int64_t getByteLength();

	virtual bool setFile(const char* filepath);

	virtual bool setOutputAudioCodec(int codecId);

	virtual void setListener(MediaWriterListener* listener);

	virtual bool setMeta(const char* key, const char* value, int size);

protected:
	void fireStatus(int status);

protected:
	FILE*	m_file;
	int64_t	m_totalBytes;
	MFormat	m_format;

	int64_t	m_startPts;
	int64_t	m_curPts;

	MediaWriterListener*	m_listener;
	PSMuxer	m_muxer;
	MediaFormat	m_fmt;

	comn::ByteBuffer	m_adtsBuffer;

};


} /* namespace av */

#endif /* PSMEDIAWRITER_H_ */
